﻿using System;
using System.Windows.Forms;
using Microsoft.Practices.Unity;

using SharedGenomics.Core.Configuration;
using SharedGenomics.Workbench.Presenters;
using SharedGenomics.Workbench.Views.WindowsForms;

namespace SharedGenomics.Workbench.Core.Configuration
{
    public class FrameworkContainerConfigurationStrategy : IContainerConfigurationStrategy
    {
        public void Configure(ContainerConfigurationContext context)
        {
            var container = context.Container;

            //setup presenter factory - this involves creating the setup pipeline
            container.RegisterType<PresenterFactory>(new ContainerControlledLifetimeManager());
            PresenterFactory presenterFactory = container.Resolve<PresenterFactory>();
            presenterFactory.AddCreationStage<CachePresenterInitialisationStage>();
            presenterFactory.AddCreationStage<BuildUpPresenterInitialisationStage>();
            presenterFactory.AddCreationStage<CreationPresenterInitialisationStage>();
            presenterFactory.AddCreationStage<InitialiseActionPresenterInitialisationStage>();

            //setup annotation wrapper stage - presenter types added here will be returned wrapped in an AnnotationWrapperPresenter
            AnnotationWrapperPresenterInitialisationStage annotationWrapperStage = new AnnotationWrapperPresenterInitialisationStage();
            annotationWrapperStage.WrapPresenter<GeneSummaryPresenter>();
            annotationWrapperStage.WrapPresenter<NcbiSummaryPresenter>();
            annotationWrapperStage.WrapPresenter<TextMinedPublicationsPresenter>();

            presenterFactory.AddCreationStage(annotationWrapperStage);

            container.RegisterType<SharedGenomics.Workbench.Views.WindowsForms.WindowsFormsViewManager>(new ContainerControlledLifetimeManager());
            container.RegisterType<IViewManager<Control>, WindowsFormsViewManager>();
            container.RegisterType<IViewDisplayer, WindowsFormsViewManager>();
        }
    }
}
